package com.ctrip.cap.common.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtil {

	public static String write2Json(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

	public static <T> T readFromJson(String str, Class<T> cls)
			throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.readValue(str, cls);
	}

}
